﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apps.IDAL;
using Apps.Models;
using Apps.IDAL.Sys;

namespace Apps.DAL.Sys
{
    public class SysRightGetModuleRightRepository :BaseRepository<SysModuleOperate>, ISysRightGetModuleRightRepository,IDisposable
    {
        public SysRightGetModuleRightRepository(DBContainer db)
            : base(db)
        {
        
        }

        public List<P_Sys_GetModule_RoleRight_Result> GetModuleRoleRight(string moduleId)
        {
            return Context.Database.SqlQuery<P_Sys_GetModule_RoleRight_Result>(
                string.Format(
"select r.id,r.name,replace(strcat('<a class=\"fa fa-check-square-o color-green\"/>' || to_char(o.name)),',','') keyCode" +
@" from SysRight a join SYSRIGHTOPERATE p on a.id = p.rightid
join sysmoduleoperate o on a.moduleid = o.moduleid and p.keycode = o.keycode
join sysrole r on a.roleid = r.id
where a.ModuleId = '{0}' and RIGHTFLAG = 1
group by r.id, r.name", moduleId)).ToList();
            //var result = Context.P_Sys_GetModule_RoleRight(moduleId).ToList();
            //    return result;
        }
        public List<P_Sys_GetModule_UserRight_Result> GetModuleUserRight(string moduleId)
        {
            return Context.Database.SqlQuery<P_Sys_GetModule_UserRight_Result>(
                string.Format(
"select ui.id,ui.truename name,replace(strcat('<a class=\"fa fa-check-square-o color-green\"/>' || to_char(o.name)),',','') keyCode" +
@" from SysRight a join SYSRIGHTOPERATE p on a.id = p.rightid
join sysmoduleoperate o on a.moduleid = o.moduleid and p.keycode = o.keycode
join sysrole r on a.roleid = r.id
join sysrolesysuser u on r.id = u.sysroleid
join sysuser ui on ui.id = u.sysuserid
where a.ModuleId = '{0}' and RIGHTFLAG = 1
group by ui.id, ui.truename ", moduleId)).ToList();
            //var result = Context.P_Sys_GetModule_UserRight(moduleId).ToList();
            //    return result;
        }
    }
  
}
